package cn.tang.tframe.common.utils.id;

import cn.tang.tframe.common.utils.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by tanghc on 17/1/22.
 */
public class DangDangIdFactory {
	static Logger logger = LoggerFactory.getLogger(DangDangIdFactory.class);
	private static final Map<String,DangDangIdGenerator> idGenerators = new ConcurrentHashMap<>();
	private DangDangIdFactory(){}
	private static class DangDangIdFactoryHolder{
		private static DangDangIdFactory instance = new DangDangIdFactory();
	}
	public static DangDangIdFactory getInstance(){
		return DangDangIdFactoryHolder.instance;
	}
	public static DangDangIdGenerator getIdGenerator(String key){
		if(StringUtils.isNotBlank(key)){
			DangDangIdGenerator dangDangIdGenerator = idGenerators.get(key);
			if(null == dangDangIdGenerator){
				dangDangIdGenerator = new DangDangIdGenerator();
				idGenerators.put(key,dangDangIdGenerator);
			}
			return dangDangIdGenerator;
		}
		return null;
	}

}